# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lsyncd
pkgver=2.2.4
pkgrel=0
_luaver=5.4
pkgdesc="Live Syncing (Mirror) Daemon"
url="https://github.com/axkibe/lsyncd"
arch="all"
license="GPL-2.0-or-later"
depends="rsync"
makedepends="$depends_dev cmake lua$_luaver lua$_luaver-dev"
options="!check" # needs passwordless ssh access to localhost
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/axkibe/lsyncd/archive/release-$pkgver.tar.gz
	fix-realpath.patch
	lpostcmd.patch
	fix-mandir.patch
	lua5.4.patch
	$pkgname.initd
	"
builddir="$srcdir"/lsyncd-release-$pkgver

prepare() {
	default_prepare
	rm -R "$builddir"/tests
}

build() {
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DLUA_COMPILER=/usr/bin/luac$_luaver \
		-DLUA_EXECUTABLE=/usr/bin/lua$_luaver \
		-DLUA_INCLUDE_DIR=/usr/include/lua$_luaver \
		-DLUA_LIBRARY=/usr/lib/lua$_luaver/liblua.so
	cmake --build .
}

package() {
	make DESTDIR="$pkgdir" install
	mkdir -p "$pkgdir/etc/lsyncd"
	cp "$builddir"/examples/*.lua \
		"$pkgdir"/etc/lsyncd/
	install -Dm755 "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"
}

sha512sums="
8f4a55e54fe0a1da1d354bf1192c4b52b05859edf02713dba84a4b596fc36866d1bffe3a8768565637fefa54ba9248a209449f007b249998217f4b9dde0f447b  lsyncd-2.2.4.tar.gz
2cebaf59d960321c2eda4ef1e0d850f62eb7eedb7ba8922a5db33a7f78c769d1a52839fbb597ae06ba576632e2abc7b92a6ba2eaf58b71b93bc877db83e25576  fix-realpath.patch
047ee8b2fae169e444c81e9b3ce0ef38713a114877cc38f6aee0594cd64c7b7d99d22ac81fe5e6ac87767956e8757731374a179800ec57fe664f058788ba482b  lpostcmd.patch
8bf810537085cf5b0408bb50e29fe1d197bc56d4dcfc8ed34c05d3a8fa2bf89c7d8091a53eda0818aa92a2db9714562186618ddb7b4fef94ebdc2d200d95387e  fix-mandir.patch
94b58b465dd8c0c84dfa033326e7acf2a5d2f37179eea07d14fd964a49016e256b2046cf16d5d50fb3b5ea71dd1e7dea21b10e860b613a46ddf3b853180ddcb4  lua5.4.patch
441b76ec944d9d74100dfca55efe871e9092b37cd49ec79a2a94e281dc0326b4def1645a827f7d3edcddc95d6e74c99621b62991396fb3693b1832c42fd86cdc  lsyncd.initd
"
